import http.server
import socketserver
import webbrowser
import threading

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print(f"游戏服务器运行在 http://localhost:{PORT}")
    print("按Ctrl+C停止服务器")
    
    # 尝试在默认浏览器中打开游戏
    try:
        webbrowser.open(f"http://localhost:{PORT}")
        print("游戏已在浏览器中打开")
    except Exception as e:
        print(f"无法自动打开浏览器: {e}")
    
    httpd.serve_forever()